
let initState:RolesState = {
    rolesList:[]
}

let rolesReducer = (state=initState,action:RolesAction)=>{
    console.log(action)
    let newState:RolesState= JSON.parse(JSON.stringify(state));
    switch(action.type){
        case "GET_LIST":
            newState.rolesList  = action.list as RolesItem[];
            return newState
        case 'UPDATE_ROLES':
            // 根据传递过来的角色id查到当前修改角色权限的索引
            let index = newState.rolesList.findIndex(item=>item.id===action.id);
            if(index===-1){
                return newState
            }
            newState.rolesList[index].children= action.newList as RolesChildrenItem[];
            return newState
        default:
            return state;
    }
}

export default rolesReducer